//implement GTimerTester
//andycai_sc 2011-05-28

#include "GTimerTester.h"
#include "GParallel/GThread.h"
#include "GParallel/GTimer.h"
#include <sys/timeb.h>
#include <ctime>
#include <cstdio>

class TestTimer : public GTimer
{
public:
	TestTimer();
	virtual ~TestTimer();

	void schedule();
};

TestTimer::TestTimer()
{
}

TestTimer::~TestTimer()
{
}

void TestTimer::schedule()
{
	struct timeb tmb;
	ftime(&tmb);
	struct tm* tmt;
	tmt = localtime(&tmb.time);
	printf("current time is %4d:%02d:%02d:%02d:%02d:%d\n",
			tmt->tm_year, tmt->tm_mon, tmt->tm_mday,
			tmt->tm_hour, tmt->tm_sec, tmb.millitm);
}

GTimerTester::GTimerTester(const string& testName) : GParallelTester(testName)
{
}

GTimerTester::~GTimerTester()
{
}

GTimerTester GTimerTester::_timerTester;

GTimerTester& GTimerTester::instance()
{
	return _timerTester;
}

void GTimerTester::testTimer()
{
	TestTimer timer;
	timer.begin(300);
	for (int i = 0; i < 20; ++i)
		GThread::sleep(1000);
	timer.cancel();
}

void GTimerTester::run()
{
	testTimer();
}
